<?php

namespace app\admin\validate;

use think\Validate;

class Works extends Validate
{
    protected $rule = [
        'title' => 'require|max:45|unique:works',
        'content' => 'require',
        'works_url' => 'requireWith:works_url,url',
        'keywords' => 'require',
        'column_id' => 'require|check_column_id',
    ];
    protected $message = [
        'title.require' => '标题必须填写',
        'keywords.require' => '关键词必须填写',
        'works_url.url' => '不是一个有效的URL地址',
        'title.max' => '标题长度不得超过45个字符',
        'title.unique' => '该标题已经存在',
        'content.require' => '内容必须填写',
        'column_id.require' => '必须选择所属栏目',
    ];
    protected $scene = [
        'create' => [],
        'update' => [],
    ];

    //验证不能在含有子栏目的栏目发表文章
    protected function check_column_id($value,$rule,$data,$field,$field_explain)
    {
        $res = infinite_classify('column',$value);

        return count($res)?'不能在该栏目下发表':true;

    }


}